package com.jxl.controller;


import com.jxl.entity.dto.RoutDTO;
import com.jxl.entity.po.Route;
import com.jxl.entity.query.RoutePageQuery;
import com.jxl.entity.vo.PageResponse;
import com.jxl.entity.vo.ResponseResult;
import com.jxl.service.IRouteService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 线路表 前端控制器
 * </p>
 *
 * @author 金小梁
 * @since 2025-06-08
 */
@Api(tags = "线路管理")
@RestController
@RequestMapping("/route")
public class RouteController {

    @Autowired
    private IRouteService routeService;


    /**
     * 新增路线
     */
    @ApiOperation("新增路线")
    @PostMapping("addRoute")
    public ResponseResult addRoute(@RequestBody RoutDTO routDTO){
        routeService.addRoute(routDTO);
        return ResponseResult.success();
    }


    @ApiOperation("分页查询")
    @PostMapping("/queryRoutes")
    public ResponseResult<PageResponse<RoutDTO>> queryVehicles(@RequestBody RoutePageQuery routePageQuery){
        PageResponse<RoutDTO> pageResponse = routeService.queryRoutes(routePageQuery);
        return ResponseResult.success(pageResponse);
    }


    @ApiOperation("删除")
    @DeleteMapping("/deleteRoute")
    public  ResponseResult deleteByIds(@RequestBody List<Long> ids){
        routeService.deleteByIds(ids);
        return ResponseResult.success();
    }

    @ApiOperation("修改")
    @PutMapping("/editRoute")
    public ResponseResult updateRoute(@RequestBody RoutDTO routDTO){
        routeService.updateRoute(routDTO);
        return ResponseResult.success();
    }


    @ApiOperation("查询所有启用线路")
    @GetMapping("/queryAllRoutes")
    public ResponseResult<List<Route>> queryAllRoutes(){
        List<Route> list = routeService.query()
                        .eq("status", 1).list();
        return ResponseResult.success(list);
    }



}
